package com.eduadmin.controller;

import com.alibaba.excel.EasyExcel;
import com.eduadmin.entity.Category;
import com.eduadmin.entity.Grade;
import com.eduadmin.listener.CategoryDataUploadListener;
import com.eduadmin.listener.GradeDataUploadListener;
import com.eduadmin.service.ICategoryService;
import com.eduadmin.service.IGradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Controller
public class CategoryController {
    //构造函数自动装配
    private final ICategoryService categoryService;
    @Autowired
    public CategoryController(ICategoryService categoryService){
        this.categoryService= categoryService;
    }
    //导入年级数据
    @RequestMapping(value = "addCategorys")
    @ResponseBody
    public String addCategorys(MultipartFile categoryFile) throws IOException {
        EasyExcel.read(categoryFile.getInputStream(), Category.class, new CategoryDataUploadListener(categoryService)).sheet().doRead();
        return "上传成功";
    }

}
